import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
// 同一个页面跳转同一个路由也会出现同样的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/hot',
    name: 'Hot',
    component: () => import(/* webpackChunkName: "about" */ '../views/hot.vue')
  },
  {
    path: '/magicBox',
    name: 'MagicBox',
    component: () => import(/* webpackChunkName: "about" */ '../views/magicBox.vue')
  },
  {
    path: '/purchase',
    name: 'Purchase',
    component: () => import(/* webpackChunkName: "about" */ '../views/purchase.vue')
  },
  {
    path: '/write',
    name: 'Write',
    component: () => import(/* webpackChunkName: "about" */ '../views/write.vue')
  },
  {
    path: '/write',
    name: 'Write',
    component: () => import(/* webpackChunkName: "about" */ '../views/write.vue')
  },
  {
    path: '/qqLogin',
    name: 'QqLogin',
    component: () => import(/* webpackChunkName: "about" */ '../components/qqLogin.vue')
  },
  {
    path: '/u_center',
    name: 'U_center',
    component: () => import(/* webpackChunkName: "about" */ '../views/u_center.vue'),
    children:[
      {
        path: '/u_center/u_manage',
        name: 'U_manage',
        component: () => import(/* webpackChunkName: "about" */ '../components/u_manage.vue'),
      },
      {
        path: '/u_center/coin_charge',
        name: 'Coin_charge',
        component: () => import(/* webpackChunkName: "about" */ '../components/coin_charge.vue'),
      },
      {
        path: '/u_center/cons_record',
        name: 'Cons_record',
        component: () => import(/* webpackChunkName: "about" */ '../components/cons_record.vue'),
      },
      {
        path: '/u_center/mark_record',
        name: 'Mark_record',
        component: () => import(/* webpackChunkName: "about" */ '../components/mark_record.vue'),
      },
      {
        path: '/u_center/charge_record',
        name: 'Charge_record',
        component: () => import(/* webpackChunkName: "about" */ '../components/charge_record.vue'),
      },
      {
        path: '/u_center/banlaceRecord',
        name: 'BanlaceRecord',
        component: () => import(/* webpackChunkName: "about" */ '../components/banlaceRecord.vue'),
      },
      {
        path: '/u_center/vip_meal',
        name: 'Vip_meal',
        component: () => import(/* webpackChunkName: "about" */ '../components/vip_meal.vue'),
      },
      {
        path: '/u_center/invite_reward',
        name: 'Invite_reward',
        component: () => import(/* webpackChunkName: "about" */ '../components/invite_reward.vue'),
      }
    ]
  }
]

const router = new VueRouter({
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.afterEach((to,from,next) => {
	document.body.scrollTop =0;
	document.documentElement.scrollTop = 0;
});

// router.beforeEach((to,from,next) => {
//   if(window.localStorage.getItem("u_Token")){
//     next();
//   }else{

//   }
// });


export default router
